<?php
/*
 * 手机客户端  我的收藏列表接口
 * 传入参数 
 * 2013-12-011
 */
include "inc/public_header.php";
include "inc/MiniaturePro.class.php";
include "func/user.php";				//用户信息处理函数
include "func/pic.php";					//图片处理函数

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0"));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键

$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$panelWidth		= $_REQUEST["panelWidth"];		//屏幕宽度
$hd_id			= $_REQUEST["hd_id"];			//活动主键

if($panelWidth<480){
	$imgWidth  = 100;
}else if($panelWidth>=480 && $panelWidth<=600){
	$imgWidth = 200;
}else {
	$imgWidth = 300;
}
	 
if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页200条
}

$reJson["success"] = "1";

//作品总数
$sql = "select count(0) as ct from new_weituo_zuopin a inner join new_weituo_gz e on a.id=e.zpid where  a.aflag='1' and a.dr='0' and e.uid='".$uid."'";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct");

//作品信息列表
$sql ="select 
				a.id
				,a.uid
				,a.aname
				,a.gz_count
				,a.ll_count
				,a.pl_count
				,a.czln
				,a.img_path
				,a.img_id
				,a.type_id
				,a.zan_count
				,e.id as mini_img_id
				,e.awidth as mini_img_width
				,e.aheight as mini_img_height
				,e.aname as mini_img_aname
		from 
				new_weituo_zuopin a	
				left join new_weituo_person d on a.uid=d.uid
				inner join new_weituo_gz f on a.id=f.zpid
				left join new_weituo_pic_size e on a.img_id=e.img_id and e.awidth='".$imgWidth."'
		where
				a.dr='0'
				and a.aflag = '1'
				and f.uid = '".$uid."'
		";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$sql = $sql."group by id limit ".($page * $pagesize).",".$pagesize;


$db->query($sql);
$worksArr = array();
$miniature = new MiniaturePro();	//构建缩略图处理类

while($db->next_record()){
	//处理生成缩略图
	$imgInfos = pic_resize(
							 $miniature
							,$db->f("img_path")
							,$db->f("mini_img_aname")
							,$imgWidth
							,$db->f("img_id")
							,$db->f("mini_img_id")
							,$db->f("mini_img_width")
							,$db->f("mini_img_height"));
	if($imgInfos["success"]=="0"){
		//图片有问题，无法显示
		continue;
	}
	$worksArr[] = array(
		"title"=>$db->f("aname")							//作品标题
		,"worksid"=>$db->f("id")							//作品id
		,"imgurl"=>$imgInfos["mini_img_url"]				//图片
		,"authorid"=>$db->f("uid")							//作者id
		,"praise"=>$db->f("zan_count")						//赞
		,"imgWidth"=>(string)$imgInfos["mini_img_width"]	//图片宽度
		,"imgHeight"=>(string)$imgInfos["mini_img_height"]	//图片高度
	);
}
$reJson["list"]=$worksArr;
echo json_encode($reJson);
?>